<%@page import="multiface.promonet.jpa.RigaProdottoReport"%>
<%@page import="multiface.promonet.jpa.Report"%>
<%@page import="multiface.promonet.jpa.Lavoro"%>
<%@page import="java.util.List"%>
<%@page import="multiface.promonet.jpa.Prodotto"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="multiface.promonet.jpa.util.PersistenceManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%
    EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
    EntityManager em = emf.createEntityManager();

    int idLav = Integer.parseInt(request.getParameter("lavoroid"));
    Lavoro lav = em.find(Lavoro.class, idLav);
    em.refresh(lav);
    Report rep = lav.getReport();
    em.refresh(rep);
    em.close();
%>
<script>
    function del(id){
        if(confirm('Vuoi eliminare il Prodotto dal Report?')){
            $.post('ActionServlet',{
                rigaid:id,
                action:'del_report_row',
                section:'job'
            },function (data){
                $('#riga_'+id).hide();
            });
        }
    }
    
    $(document).ready(function() {
	
        $("a.group").fancybox({
            'transitionIn':'elastic',
            'transitionOut':'elastic',
            'speedIn':400, 
            'speedOut':200, 
            'overlayShow':false,
            'autoScale': true,
            'type': 'iframe',
            'scrolling': 'no',
            'width': 350,
            'height': 200
        });
	
    });
    
    function refresh_fancybox(){
        $("a.group").fancybox({
            'transitionIn':'elastic',
            'transitionOut':'elastic',
            'speedIn':400, 
            'speedOut':200, 
            'overlayShow':false,
            'autoScale': true,
            'type': 'iframe',
            'scrolling': 'no',
            'width': 350,
            'height': 200
        });
    }
</script>
<div id="center">
    <table id="center-table"  class="center-table">
        <tr style="background-color: #00A551;color:white;font-weight: bold;height: 24px;">
            <td style="width: 20px;">N.</td>
            <td style="width: 250px;">Prodotto</td>
            <td>Prezzo</td>
            <td>Promo</td>
            <td>Stock</td>
            <td>Venduto</td>
            <td style="width: 20px;"></td>
            <td style="width: 20px;"></td>
        </tr>
        <%
            int i = 0;
            for (RigaProdottoReport riga : rep.getRigaProdottoReportList()) {
                i++;
                int rid = riga.getIdRigaProdottoReport();
        %>
        <tr id="riga_<%=rid%>" class="center-table-tr">
            <td style="width: 20px;"><%=i%></td>
            <td style="width: 200px;"><%=riga.getProdotto().getNome()%></td>
            <td id="riga_prezzo_<%=rid%>"><%=riga.getPrezzo()%></td>
            <td id="riga_promo_<%=rid%>"><%=riga.getReport().getPromozione().getNome()%></td>
            <td id="riga_stock_<%=rid%>"><%=riga.getStock()%></td>
            <td id="riga_venduti_<%=rid%>"><%=riga.getVenduti()%></td>
            <td style="width: 20px;"><a class="group" href="promoter/popup/mod_report_row.jsp?rigaid=<%=riga.getIdRigaProdottoReport()%>"><img src="engine/img/btn/edit.png"/></a></td>
            <td style="width: 20px;"><a href="javascript:del(<%=riga.getIdRigaProdottoReport()%>);"><img src="engine/img/btn/del.png"/></a></td>
        </tr>
        <%                }
        %>
    </table>
</div>
